/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "AppDelegate.h"
#import <CodePush/CodePush.h>

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

// wechat
#import <React/RCTLinkingManager.h>
// splash screen
#import "RNSplashScreen.h"

// Orientation 视频全屏
#import "Orientation.h"

// 阿里百川
// #import <AlibcTradeSDK/AlibcTradeSDK.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"coupon"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  [RNSplashScreen show];
  return YES;
}



- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [CodePush bundleURL];
#endif
}


// ios 8.x or older
//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
//  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
//{
//  return [RCTLinkingManager application:application openURL:url
//                      sourceApplication:sourceApplication annotation:annotation];
//}

// ios 9.0+
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
            options:(NSDictionary<NSString*, id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}


// Orientation 视频全屏
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
  }
  
  return [Orientation getOrientation];
}



//  - (BOOL)application:(UIApplication *)application {
//    // 百川平台基础SDK初始化，加载并初始化各个业务能力插件
//    [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{

//    } failure:^(NSError *error) {
//      NSLog(@"Init failed: %@", error.description);
//    }];

//    // 开发阶段打开日志开关，方便排查错误信息
//    // 默认调试模式打开日志,release关闭,可以不调用下面的函数
// //    [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];

//    // 配置全局的淘客参数
//    // 如果没有阿里妈妈的淘客账号,setTaokeParams函数需要调用
// //   AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
// //   taokeParams.pid = @"mm_XXXXX"; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
// //   [[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];

//    // 设置全局的app标识，在电商模块里等同于isv_code
//    // 没有申请过isv_code的接入方,默认不需要调用该函数
// //   [[AlibcTradeSDK sharedInstance] setISVCode:@"your_isv_code"];

//    // 设置全局配置，是否强制使用h5
//    [[AlibcTradeSDK sharedInstance] setIsForceH5:NO];

//    return YES;
//  }



@end
